checkToken();

function checkToken() {
	var systoken = sessionStorage.getItem('systoken');
	if(!systoken) {
		alert("请先登录!")
		window.location.href = "login.html"
	}
}

var urlA = path + "/theoryRecords/getAll";

layui.use(['table', 'laypage', 'layer', 'laydate', 'jquery', 'form'], function() {
	var form = layui.form
	var laydate = layui.laydate;
	var $ = layui.$

	laydate.render({
		elem: '.startTime',
		type: 'date'
	});
	laydate.render({
		elem: '.endTime',
		type: 'date'
	});
	laydate.render({
		elem: '.updateTime',
		type: 'datetime'
	});
	//日期时间选择器

	getShiCao();
	form.on("select(pid)", function() {
		$(".shijian").val("");
		if($(".type  option:selected").val() == "0") {
			$(".bianhao").css("display", "block")
			urlA = path + "/operationRecords/getAll";
			$("#leix").find("option").remove();
			$("#leix").append("<option value=\"\">请选择培训科目</option>",
				"<option value=\"0\">雷达管制基础模拟机</option>",
				"<option value=\"1\">机场管制基础模拟机</option>",
				"<option value=\"2\">程序管制基础模拟机</option>"
			);
			getTheoryRecord();
		} else {
			$(".bianhao").css("display", "none");
			$("#leix").find("option").remove();
			$("#leix").append("<option value=\"\">请选择培训科目</option>",
				"<option value=\"0\">雷达管制理论</option>",
				"<option value=\"1\">机场管制理论</option>",
				"<option value=\"2\">程序管制理论</option>",
				"<option value=\"3\">空管基础理论</option>")
			urlA = path + "/theoryRecords/getAll";
			getShiCao();
		}
		form.render('select');
	})
})

$(".startSearch").click(function() {
	if($(".type  option:selected").val() == "0") {
		getTheoryRecord();
	} else {
		getShiCao();
	}
	//  if($(".type  option:selected").val()=="0"){
	//    getTheoryRecord();
	// }else{
	//      getShiCao();
	// }

});

function getShiCao() {
	layui.use(['table', 'laypage', 'layer', 'laydate', 'jquery', 'form'], function() {
		var laypage = layui.laypage,
			form = layui.form,
			layer = layui.layer,
			$ = layui.$,
			laydate = layui.laydate;
		var table = layui.table;

		var id = $(".id").val();
		var classId = $(".classId").val();
		//		var theoryType = $(".theoryType").val();
		var trainingType = $(".trainingType  option:selected").val();
		var courseType = $("#courseType  option:selected").val();
		var theoryType = $(".theoryType  option:selected").val();
		var type = $(".type option:selected").val();
		var startTime = $(".startTime").val();
		var endTime = $(".endTime").val();
		var theoryId = $(".theoryId").val();
		var subjectId = $(".subjectId").val();
		var signId = $(".signId").val();
		var teacherName = $(".teacherName").val();
		var date = $(".startTime").val();
		// var hour = $(".hour").val();
		// var content = $(".content").val();
		// var signCount = $(".signCount").val();
		// var name = $(".name").val();
		var stamp = new Date().getTime();
		var systoken = sessionStorage.getItem('systoken');

		var param = {
			type: type,
			/*id: id,
			classId: classId,*/
			// operationType:operationType,
			trainingType: trainingType,
			endTime: endTime,
			startTime: startTime,
			teacherName: teacherName,
			theoryType: theoryType,
			/*培训科目*/
			// courseType:courseType,
			theoryId: theoryId,
			/*subjectId: subjectId,*/
			/*signId: signId,*/
			// date: date,
			// hour: hour,
			// content: content,
			// signCount: signCount,

			stamp: stamp,
			version: 0,
			visit_plat: 1,
			visit_type: 0,
			is_used: 0,
		};
		param = JSON.stringify(param);

		var total
		var defaultpageSise = 10;
		window.ins1 = _render(defaultpageSise);

		function _render(pageSize) {
			var width = $(document).width();
			table.render({
				elem: '#tlihunRest',
				height: 600,
				title: '教案列表',
				method: 'post',
				url: urlA,
				width: 100,
				page: true,
				where: {param: param},
				headers: {Authorization: systoken},
				skin: 'row',
				even: true,
				// autoSort: true,
				loading: true,
				parseData: function(res) {
					var ros = res.rows;
					var status = res.status;
					var info = '';
					if(status == '000') {
						info = res.info
						total = res.total;
						for(var i = 0; i < res.rows.length; i++) {
							res.rows[i].courseType = '理论课'
							if(res.rows[i].theoryType == "2") {
								res.rows[i].theoryType = "程序管制理论"
							} else if(res.rows[i].theoryType == "1") {
								res.rows[i].theoryType = "机场管制管制理论"
							} else if(res.rows[i].theoryType == "3") {
								res.rows[i].theoryType = "空管基础理论"
							} else if(res.rows[i].theoryType == "0") {
								res.rows[i].theoryType = "雷达管制理论"
							}

							if(res.rows[i].trainingType == "0") {
								res.rows[i].trainingType = "岗前培训"
							} else if(res.rows[i].trainingType == "1") {
								res.rows[i].trainingType = "岗位培训"
							} else if(res.rows[i].trainingType == "2") {
								res.rows[i].trainingType = "复习"
							} else if(res.rows[i].trainingType == "3") {
								res.rows[i].trainingType = "熟练"
							} else if(res.rows[i].trainingType == "4") {
								res.rows[i].trainingType = "附加"
							} else if(res.rows[i].trainingType == "5") {
								res.rows[i].trainingType = "补习"
							} else if(res.rows[i].trainingType == "6") {
								res.rows[i].trainingType = "追加"
							}

						}
					} else if(status == '001') {
						info = res.rows
					} else if(status == '401') {
						info = '请您重新登录！';
					}
					return {
						"code": res.status,
						"msg": info,
						"count": res.total,
						"data": res.rows
					};
				},
				done: function(res, curr, count) {
					laypage.render({
						elem: 'fy',
						count: total //数据总数
							,
						jump: function(obj) {}
					});
				},
				totalRow: true,
				limit: 10,
				width: width * 0.9,
				cols: [
					[{
							field: 'courseType',
							title: '课程类型',
							align: 'center',
							width: 130,
							 
						},
						{
							field: 'trainingType',
							title: '培训类别',
							align: 'center',
							width: 130
						},
						{
							field: 'theoryType',
							title: '培训科目',
							align: 'center',
							width: 130
						},
						//                      {field:'teacherName', title:'教员姓名',align: 'center'},
						{
							field: 'content',
							title: '内容',
							align: 'center',
							width: 100
						},
						{
							field: 'updateTime',
							title: '开始时间',
							align: 'center',
							width: 110
						},
						{
							field: 'createTime',
							title: '结束时间',
							align: 'center',
							width: 110
						},
						{
							field: 'time',
							title: '时长（分钟）',
							align: 'center',
							width: 100
						},
					]
				],
				done: function(res, curr, count) {
					$('thead span').css({
						"font-size": "16px!important"
					});
				},
				limit: pageSize,
			});
		};

		//监听排序
		table.on('sort(tlihunRest)', function(obj) {
			layer.msg('已经完成排序！ ' + obj.field + ' ' + obj.type);
			//服务端排序
			table.reload('tlihunRest', {
				initSort: obj
					//,page: {curr: 1}
					,
				where: {
					key: obj.field,
					order: obj.type
				}
			});
		});

		var $ = layui.jquery,
			active = {
				parseTable: function() {
					table.init('parse-table-demo', {
						limit: 3
					});
				},
				add: function() {
					table.addRow('tlihunRest')
				}
			};
		$('i').on('click', function() {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});
		$('.layui-btn').on('click', function() {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		})

		var type = $(".type option:selected").val();
	});
}

function getTheoryRecord() {
	layui.use(['table', 'laypage', 'layer', 'laydate', 'jquery', 'form'], function() {
		var laypage = layui.laypage,
			form = layui.form,
			layer = layui.layer,
			$ = layui.$,
			laydate = layui.laydate;
		var table = layui.table;

		var id = $(".id").val();
		var classId = $(".classId").val();
		//		var theoryType = $(".theoryType").val();
		// var courseType = $("#courseType  option:selected").val();
		var theoryType = $(".theoryType  option:selected").val();
		var type = $(".type option:selected").val();
		var startTime = $(".startTime").val();
		var endTime = $(".endTime").val();
		var theoryId = $(".theoryId").val();
		var subjectId = $(".subjectId").val();
		var signId = $(".signId").val();
		var teacherName = $(".teacherName").val();
		var date = $(".startTime").val();
		var hour = $(".hour").val();
		var content = $(".content").val();
		var signCount = $(".signCount").val();
		var name = $(".name").val();
		var stamp = new Date().getTime();
		var systoken = sessionStorage.getItem('systoken');

		var param = {
			trainingType: $("#operationType option:selected").val(), // 模拟机培训类别  岗前  岗位  追加
			type: type,
			// courseType:courseType,
			operationType: theoryType, //模拟机培训科目   雷达   空管   机场
			endTime: endTime,
			startTime: startTime,
			/*id: id,

			endTime:endTime,
			startTime:startTime,
			teacherName: teacherName,
			theoryId: theoryId, //理论课名称
			/*signId: signId,*/
			date: date,
			hour: hour,
			content: content,
			signCount: signCount,

			stamp: stamp,
			version: 0,
			visit_plat: 1,
			visit_type: 0,
			is_used: 0,
		};
		param = JSON.stringify(param);
		var defaultpageSise = 10;
		window.ins1 = _render(defaultpageSise);

		function _render(pageSize) {
			var width = $(document).width();
			table.render({
				elem: '#tlihunRest',
				height: 600,
				title: '教案列表',
				method: 'post',
				url: urlA,
				width: 100,
				page: true,
				where: {
					param: param
				},
				headers: {
					Authorization: systoken
				},
				skin: 'row',
				even: true,
				// autoSort: true,
				loading: true,
				parseData: function(res) {
					var status = res.status;
					var info = '';
					if(status == '000') {
						info = res.info
						var ros = res.rows;
						for(var i = 0; i < ros.length; i++) {
							res.rows[i].courseType = '模拟机课'
							if(res.rows[i].operationType == "2") {
								res.rows[i].operationType = "程序管制基础模拟机"
							} else if(res.rows[i].operationType == "1") {
								res.rows[i].operationType = "机场管制基础模拟机"
							} else if(res.rows[i].operationType == "3") {
								res.rows[i].operationType = "空管基础基础模拟机"
							} else if(res.rows[i].operationType == "0") {
								res.rows[i].operationType = "雷达管制基础模拟机"
							}
							if(res.rows[i].trainingType == "0") {
								res.rows[i].trainingType = "岗前培训"
							} else if(res.rows[i].trainingType == "1") {
								res.rows[i].trainingType = "岗位培训"
							} else if(res.rows[i].trainingType == "2") {
								res.rows[i].trainingType = "复习"
							} else if(res.rows[i].trainingType == "3") {
								res.rows[i].trainingType = "熟练"
							} else if(res.rows[i].trainingType == "4") {
								res.rows[i].trainingType = "附加"
							} else if(res.rows[i].trainingType == "5") {
								res.rows[i].trainingType = "补习"
							} else if(res.rows[i].trainingType == "6") {
								res.rows[i].trainingType = "追加"
							}
						}
					} else if(status == '001') {
						info = res.rows
					} else if(status == '401') {
						info = '请您重新登录！';
					}
					return {
						"code": res.status,
						"msg": res.rows,
						"count": res.total,
						"data": res.rows
					};
				},
				done: function(res, curr, count) {},
				totalRow: true,
				limit: 10,
				width: width * 0.9,
				cols: [
					[{
							field: 'courseType',
							title: '课程类型',
							align: 'center',
							width: 100
						},
						{
							field: 'trainingType',
							title: '培训类别',
							align: 'center',
							width: 100
						},
						{
							field: 'operationType',
							title: '培训科目',
							align: 'center',
							templet: '#theoryType',
							width: 120
						},
						{
							field: 'studentName',
							title: '学员姓名',
							align: 'center',
							width: 100
						},
						{
							field: 'number',
							title: '练习编号',
							width: '100',
							align: 'center',
							width: 100
						},
						{
							field: 'totalScore',
							title: '得分',
							align: 'center',
							width: 80
						},
						{
							field: 'startTime',
							title: '开始时间',
							align: 'center',
							width: 110
						},
						{
							field: 'endTime',
							title: '结束时间',
							align: 'center',
							width: 110
						},
						{
							field: 'time',
							title: '时长(分钟)',
							align: 'center',
							width: 100
						}
					]
				],
			});
		};

		//监听排序
		table.on('sort(tlihunRest)', function(obj) {
			layer.msg('已经完成排序！ ' + obj.field + ' ' + obj.type);
			//服务端排序
			table.reload('tlihunRest', {
				initSort: obj,
				where: {
					key: obj.field,
					order: obj.type
				}
			});
		});
		var $ = layui.jquery,
			active = {
				parseTable: function() {
					table.init('parse-table-demo', {
						limit: 3
					});
				},
				add: function() {
					table.addRow('tlihunRest')
				}
			};
		$('i').on('click', function() {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});
		$('.layui-btn').on('click', function() {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		})

		var type = $(".type option:selected").val();
	});
}

sessionStorage.removeItem("menu");
sessionStorage.removeItem("curMenu");